package com.example.basic.web.controller.basicDataValue;


import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.basicDataValue.BasicDataValue;
import com.example.basic.web.service.basicDataValue.BasicDataValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 配置管理内容 前端控制器
 * </p>
 */
@Api(value = "配置管理内容相关操作", tags = {"配置管理内容"})
@RestController
@RequestMapping("/api/v1/byg/basicDataValue")
public class BasicDataValueController {

    @Resource
    private BasicDataValueService basicDataValueService;

    @Log(title = "配置管理内容", description = "新增更新")
    @ApiOperation(value="新增更新",notes = "新增更新")
    @PostMapping("/addOrUpdate")
    public Result<BasicDataValue> addOrUpdate(@ApiParam(name = "basicDataValue", value = "模型", required = true) @RequestBody BasicDataValue basicDataValue, HttpServletRequest request) {
        return ResultGenerator.genSuccessResult(basicDataValueService.addOrUpdate(basicDataValue));
    }

    @Log(title = "配置管理内容", description = "删除")
    @ApiOperation(value="删除",notes = "删除")
    @PostMapping("/remove")
    public Result remove(
            @ApiParam(name = "value", value = "值", required = true) @RequestParam String value,
            @ApiParam(name = "basicCode", value = "配置管理主代码", required = true) @RequestParam String basicCode) {
        return ResultGenerator.genSuccessResult(basicDataValueService.remove(basicCode,value));
    }

    @Log(title = "配置管理内容", description = "删除")
    @ApiOperation(value="查询配置管理内容详情",notes = "查询配置管理内容详情")
    @PostMapping("/detail")
    public Result detail(@ApiParam(name = "basicCode", value = "配置管理主代码", required = true) @RequestParam String basicCode,
                         @ApiParam(name = "value", value = "值", required = true) @RequestParam String value) {
        return ResultGenerator.genSuccessResult(basicDataValueService.detail(basicCode,value));
    }

    @Log(title = "配置管理内容", description = "删除")
    @ApiOperation(value="查询配置管理内容列表",notes = "查询配置管理内容列表")
    @PostMapping("/queryList")
    public Result queryList(@ApiParam(name = "searchParam", value = "模糊搜索（拼音、五笔、名称、代码）") @RequestParam(required = false) String searchParam,
                            @ApiParam(name = "basicCode", value = "配置管理主代码") @RequestParam String basicCode,
                            @ApiParam(value = "页码",name = "page") @RequestParam(defaultValue = "0") Integer page,
                            @ApiParam(value = "数量",name = "size") @RequestParam(defaultValue = "0")  Integer size) {
        return ResultGenerator.genSuccessResult(basicDataValueService.queryList(page,size,basicCode,searchParam));
    }
}